package com.aat.dxfy.redis.pool;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisSentinelPool;

public class CustomPool {
	private JedisSentinelPool jedisSentinelPool = null;
	private JedisPool jedisPool = null;
	private boolean isSentinelMode = false;
	
	public CustomPool(JedisSentinelPool poolInstance){		
		this.isSentinelMode = true;
		this.jedisSentinelPool=poolInstance;
	}
	public CustomPool(JedisPool poolInstance){		
		this.isSentinelMode = false;
		this.jedisPool=poolInstance;
	}
	
	public Jedis getResource(){
		if(isSentinelMode){
			return jedisSentinelPool.getResource();
		}else{
			return jedisPool.getResource();
		}
	}
	
	public void returnResource(Jedis jedis) {
		if(jedis!=null){ 
			if(isSentinelMode){
				jedisSentinelPool.returnResource(jedis);
			}else{
				jedisPool.returnResource(jedis);
			}
		}
	}
}
